package cn.itrigger.dynamic.sql;

import cn.itrigger.dynamic.sql.condition.VisitableCondition;
import cn.itrigger.dynamic.sql.condition.impl.IsEqualTo;
import cn.itrigger.dynamic.sql.condition.impl.IsLessThan;
import cn.itrigger.dynamic.sql.select.QueryExpressionDSL;
import cn.itrigger.dynamic.sql.select.SelectDSL;
import cn.itrigger.dynamic.sql.select.SelectModel;
import cn.itrigger.dynamic.sql.structure.BasicColumn;
import cn.itrigger.dynamic.sql.structure.BindableColumn;

import java.util.function.Supplier;

/**
 * @author admin
 * @date 2018/9/26
 **/
public interface SqlBuilder {

    static QueryExpressionDSL.FromGatherer<SelectModel> select(BasicColumn ... selectList) {
        return SelectDSL.select(selectList);
    }

    static <T>IsEqualTo<T> isEqualTo(T value) {
        return isEqualTo(() -> value);
    }

    static <T> IsEqualTo<T> isEqualTo(Supplier<T> valueSupplier) {
        return IsEqualTo.of(valueSupplier);
    }

    static <T> SqlCriterion<T> and(BindableColumn<T> column, VisitableCondition<T> condition) {
        return SqlCriterion.withColumn(column)
                .withConnector("and")
                .withCondition(condition)
                .build();
    }

    static <T> IsLessThan<T> isLessThan(T value) {
        return isLessThan(() -> value);
    }

    static <T> IsLessThan<T> isLessThan(Supplier<T> valueSupplier) {
        return IsLessThan.of(valueSupplier);
    }
}
